package com.feature.learn.sftest;

/**
 * Copyright (C), 2015-2021, 顺丰科技有限公司
 *
 * @author 01390942
 * @Description
 * @create 2021/5/18
 * @since 1.0.0
 */
public class TestMain {
    public static void main(String[] args) {
        String reasonNumsList[] = {"1","2"};
        int reasonNums = 0;
        for (String item : reasonNumsList) {
            reasonNums += Math.pow(2, Integer.valueOf(item) - 1F);
        }

        System.out.println(reasonNums);
        System.out.println(decodeInt(reasonNums));
    }

    static String decodeInt(int extInt) {
        if (extInt < 0) {
            return "";
        }

        StringBuilder res = new StringBuilder();

        String ext_str = Integer.toBinaryString(extInt);
        char[] ext_array = ext_str.toCharArray();
        for (int i = ext_array.length - 1; i >= 0; i--) {
            int tem = 0;
            if (ext_array[i] == '0') {
                continue;
            } else {
                tem += Math.pow(2, ext_array.length - i - 1d);
                Double tem_double = (Math.log(tem) / Math.log(2));
                res.append(String.valueOf(tem_double.intValue() + 1));
                if (i > 0) {
                    res.append(",");
                }
            }
        }
        return res.toString();
    }
}